package com.alm.web.controller.alm;

import com.alm.common.core.domain.AjaxResult;
import com.alm.common.enums.CommandTypeEnum;
import com.alm.common.enums.ExceptionConditionEnum;
import com.alm.handle.core.domain.entity.rq.SendCommandRq;
import com.alm.handle.service.ApiService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @author ywy
 * @date 2024/8/21
 * 应用服务api
 */
@RestController
@RequestMapping("/alm/api")
public class ApiController {

    @Resource
    private ApiService apiService;

    /**
     * 配置设备
     * @param request
     * @param rq
     * @return
     */
    @PostMapping("/send_command")
    public AjaxResult sendCommand(HttpServletRequest request, @RequestBody SendCommandRq rq) {

        String authStr = request.getHeader("alm");
        if (StringUtils.isBlank(authStr) || StringUtils.equals(authStr, "ALM_DEVICE")) {
            return AjaxResult.buildCodeAndMsg(50001, "认证失败");
        }

        return apiService.sendCommand(rq);
    }


}
